package com.demo.controller.multipart;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.Scanner;

/**
 * Created on 2016/7/13.
 */
@Controller
@RequestMapping("/upload")
public class UploadController {

    @RequestMapping("/up1")
    @ResponseBody
    public Object up1(HttpServletRequest req, MultipartRequest request) throws Exception {
        System.out.println("req = " + req);
        System.out.println("request = " + request);
        StringBuilder stringBuilder = new StringBuilder();
        Scanner sc = new Scanner(request.getFile("file").getInputStream());
        while (sc.hasNextLine()) {
            stringBuilder.append(sc.nextLine().trim() + "\n");
        }
        sc.close();
        return stringBuilder;
    }
}
